<template>
	<view class="loginContainer">
		<block>
			<text>自动登录中...</text>
		</block>
	</view>


</template>

<script>
	export default {
		data() {
			return {
				pageUrl: '',
			}
		},
		onLoad() {
			//获取当前页面地址
			let code = this.$route.query.code ?? ''
			// console.log("this.$route.query",this.$route.query.code)
			// console.log("this.$utils.getUrlParam('code')",code)
			// console.log("code ==== ",code)
			if (code != '') {
				this.authLoginApi(code);
			} else {
				this.pageUrl = encodeURIComponent(window.location.href);
				let localUrl = encodeURIComponent(window.location.href); //获取当前页面地址
				console.log("getApp().globalData.authUrl ==== ", getApp().globalData.authUrl)
				console.log("getApp().globalData.appid ==== ", getApp().globalData.appid)
				window.location.href = getApp().globalData.authUrl +
					"/cas/oauth2.0/authorize?response_type=code&client_id=" + getApp().globalData.appid +
					"&redirect_uri=" + localUrl;
			}

		},
		methods: {
			authLoginApi(code) {
				uni.request({
					// 请求路径
					url: getApp().globalData.serverUrl + '/auth/auth/api/hzsfAuthorizeLogin',
					// 请求参数code
					data: {
						channelId: getApp().globalData.channelId,
						code: code
					},
					method: 'GET',
					success(res) {
						console.log(res);
						if (res.data.code == "10000") {
							getApp().globalData.token = res.data.data.token;
							uni.setStorage({
								key: 'token',
								data: res.data.data.token
							});
							uni.reLaunch({
								url: '/pages/index/index'
							});
						} else {
							uni.showToast({
								title: res.data.msg,
								icon: 'none'
							})
						}

					}
				})

			},
		}
	}
</script>

<style>
	.loginContainer {
		width: 100%;
		height: 100vh;
		background: #FFFFFF;
		overflow: hidden;
	}

	.txtOverFlow {
		overflow: hidden;
		text-overflow: ellipsis;
		white-space: nowrap;
	}

	.flex {
		display: flex;
	}

	.loginIcon {
		width: 369rpx;
		height: 369rpx;
		display: block;
		margin: 0 auto;
		margin-top: 31rpx;
	}

	.selectSchoolBox {
		width: 88%;
		height: 98rpx;
		line-height: 98rpx;
		margin: 80rpx 45rpx 45rpx 45rpx;
		background: #F6F6F6;
		border-radius: 49rpx;
	}

	.inputBox {
		margin-left: 46rpx;
	}

	.moreIcon3 {
		width: 66rpx;
		height: 16rpx;
		position: absolute;
		right: 20px;
		top: 43%;
	}

	.loginBtnBox {
		width: 88%;
		height: 98rpx;
		line-height: 98rpx;
		margin: 80rpx 45rpx 45rpx 45rpx;
		background: linear-gradient(90deg, #19AD78, #1EBE85);
		border-radius: 49rpx;
		text-align: center;
		font-size: 32rpx;
		color: #FFFFFF;
	}

	.wxIcon {
		width: 32rpx;
		height: 32rpx;
		margin-right: 13rpx;
		margin-top: 36rpx;
		margin-left: 34%;
	}

	.inputBox2 {
		width: 85%;
		height: 30px;
		line-height: 30px;
		border: 1px solid #efefef;
		border-radius: 10px;
		margin: 0 auto;
		padding: 10px 0 10px 10px;
		margin-bottom: 10px;
	}

	.inputVal {
		margin-top: 4px;
		width: 85%;
	}

	.imgCodeUrl {
		width: 242px;
		height: 30px;
		margin-right: 14px;
	}
</style>